﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Zatify.Domain.Abstract;
using Zatify.WebUI.Infrastructure;
using Zatify.WebUI.Admin.Models;
using Zatify.Domain.Data;
using Zatify.WebUI.Infrastructure.Filters;
using Zatify.WebUI.Infrastructure.Absrtact;

namespace Zatify.WebUI.Areas.Admin.Controllers
{
    [ZatifyAdminAuthorizeAttribute]
    [Utils.MyRequireHttps]
    public class RatesController : AdminBaseController
    {
        private IZatifyRepository repository;

        protected override AdminModules AdminModule
        {
            get
            {
                return AdminModules.Rates;
            }
        }

        public RatesController(IZatifyRepository repository, IZatifyAuthProvider authProvider)
        {
            this.repository = repository;
        }

        [HttpGet]
        public ActionResult List()
        {
            return View(new RatesViewModel()
            {
                BaseCostTimings = repository.BaseCostTimings.ToList(),
                ProximityRadiuses = repository.ProximityRadiuses.ToList(),
                ProximityRadiusOutside = repository.ProximityRadiusesOutside.ToList()
            });
        }

        [HttpPost]
        public ActionResult SaveBaseCostTimings(ICollection<BaseCostTiming> BaseCostTimings)
        {
            if (ModelState.IsValid)
            {
                repository.BaseCostTimingsUpdate(BaseCostTimings);
            }

            return RedirectToAction("List");
        }

        [HttpPost]
        public ActionResult SaveProximityRaduises(ICollection<ProximityRadius> ProximityRadiuses)
        {
            if (ModelState.IsValid)
            {
                repository.ProximityRadiusesUpdate(ProximityRadiuses);
            }

            return RedirectToAction("List");
        }

        [HttpPost]
        public ActionResult SaveUsersRegisteredOutsideOfAreas(ICollection<ProximityRadiusOutside> proximityRadiusOutside)
        {
            if (ModelState.IsValid)
            {
                repository.ProximityRadiusesOutsideUpdate(proximityRadiusOutside);
            }

            return RedirectToAction("List");
        }
    }
}
